package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcNurEntity;
import com.dhcc.cdc.busi.service.ICdcNurService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 护理病历
 * 
 * @ClassName: CdcNurController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:07
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcnur")
public class CdcNurController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcnur/";

	@Autowired
	private ICdcNurService cdcNurService;
	

    /**
     * 跳转到护理病历列表首页
     */
    @RequestMapping("")
    @Permission("cdcnur:list")
    public String index() {
        return PREFIX + "cdcnur.html";
    }
	
    /**
     * 跳转到新增护理病历
     */
    @RequestMapping("/to_add")
    @Permission("cdcnur:add")
    public String toAdd() {
        return PREFIX + "cdcnur_add.html";
    }
	
	/**
     * 跳转到修改护理病历
     */
    @RequestMapping("/to_update/{cdcNurId}")
    @Permission("cdcnur:update")
    public String toUpdate(@PathVariable Long cdcNurId, Model model) {
        CdcNurEntity cdcNur = this.cdcNurService.selectById(cdcNurId);
        model.addAttribute("cdcNur",cdcNur);
        return PREFIX + "cdcnur_edit.html";
    }

    /**
     * 获取护理病历列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcnur:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcNurEntity> page = new PageFactory<CdcNurEntity>().defaultPage();
        List<CdcNurEntity> result = this.cdcNurService.page(page,params);
        page.setRecords((List<CdcNurEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增护理病历
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcnur:add")
    @BussinessLog(value = "新增护理病历")
    public Object add(CdcNurEntity cdcNur) {
        if (CommonUtil.isOneEmpty(cdcNur)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcNur.insert();
        return R.ok();
    }

    /**
     * 删除护理病历
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcnur:delete")
    @BussinessLog(value = "删除护理病历")
    public Object delete(@RequestParam Long cdcNurId) {
	
        this.cdcNurService.deleteById(cdcNurId);

        return R.ok();
    }

    /**
     * 修改护理病历
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcnur:update")
    @BussinessLog(value = "修改护理病历")
    public Object update(CdcNurEntity cdcNur) {
        if (CommonUtil.isOneEmpty(cdcNur)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcNurEntity old = this.cdcNurService.selectById(cdcNur.getId());

        old.setEpisodeId(cdcNur.getEpisodeId());
        old.setXcode(cdcNur.getXcode());
        old.setDescription(cdcNur.getDescription());
        old.setContent(cdcNur.getContent());
        old.setNurDate(cdcNur.getNurDate());
        old.setBurUserId(cdcNur.getBurUserId());
        old.setDataId(cdcNur.getDataId());
        old.setIsActive(cdcNur.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
